; $VER: FinalWriter-030_Install 1.11 (4.11.95)

(set version "4.0")

(onerror (exit (quiet)))

(message
	"\n\nFinalWriter " version " '030"
	"\nCopyright 1995 Martin Berndt"
	"\n\n\n!!! This Patch is SHAREWARE !!!"
	"\n\nPlease read the \"ReadMe.txt\" file."
)

(set @default-dest
	(askdir
		(prompt "Where is your FinalWriter Drawer?")
		(help @askfile-help)
		(default "SYS:FinalWriter")
		(newpath)
	)
)

(set language
	(askchoice
		(prompt "Select your version")
		(help @askchoice-help)
		(choices "US1  26-Jul-95 (American English)"
			 "US2  23-Aug-95 (American English)"
			 "US3   5-Oct-95 (American English)")
	)
)

(set backup
	(askoptions
		(prompt "Options")
		(help @askoptions-help)
		(choices "Create Backup Files")
	)
)

(set n 0)
(set percent 0)

(while (set name (select n "FinalWriter" "swpost.library" "swshell.library"
			   "cachemap.library" "qfont.library" "")) (
	(set n (+ n 1))
	(complete percent)
	(if (= n 1)
		(set file name)
		(set file ("FWLibs/%s" name))
	)
	(set newfile (tackon @default-dest file))
	(set oldfile (cat newfile ".bak"))
	(if (= (exists newfile) 0)
		(abort name " not found!")
	)
	(rename newfile oldfile)
	(if (< n 4) (
		(if (= n 1) (
			(if (= language 0) (
				(working "\n\nUpdating to new version")
				(if (<> (run ("spatch \"-o%s\" \"-p%sUS1.pch\" \"%s\"" newfile name oldfile)) 0) (
					(rename oldfile newfile)
					(abort "Wrong Version!")
				))
				(delete oldfile)
				(rename newfile oldfile)
				(set language 1)
			))
			(set name (cat name (select language "US1" "US2" "US3")))
		))
		(working "\n\nPatching\n" newfile)
		(if (<> (run ("spatch \"-o%s\" \"-p%s.pch\" \"%s\"" newfile name oldfile)) 0) (
			(rename oldfile newfile)
			(abort "Wrong Version!")
		))
		(set percent (+ percent 30))
	) (
		(copyfiles
			(prompt "Copying " name)
			(help @copyfiles-help)
			(source name)
			(dest (tackon @default-dest "FWLibs"))
			(optional "force" "askuser")
		)
		(set percent (+ percent 5))
	))
	(if (= backup 0) (delete oldfile))
))
